package org.android.bbox.generic;

import org.android.bbox.R;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.text.SpannableString;
import android.text.method.LinkMovementMethod;
import android.text.util.Linkify;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.TextView;

public class ActivityUtils
{
	public static boolean menuItem(Activity a, int featureId, MenuItem item)
	{
		String current = item.toString();
		if (current.equals(a.getResources().getString(R.string.menu_quit)))
		{
			a.finish();
		}
		else
			if (current.equals(a.getResources().getString(R.string.menu_about)))
			{
				final AlertDialog d = new MyOtherAlertDialog().create(a);
				d.show();
			}

		return false;
	}

	public static boolean menuOptions(Activity a, Menu menu)
	{
		MenuInflater inflater = a.getMenuInflater();
		inflater.inflate(R.menu.menu, menu);
		return true;
	}
	public static class MyOtherAlertDialog {

		 public static AlertDialog create(Context context) {
		  final TextView message = new TextView(context);
		  // i.e.: R.string.dialog_message =>
		            // "Test this dialog following the link to dtmilano.blogspot.com"
		  final SpannableString s = 
		               new SpannableString(context.getText(R.string.about_txt));
		  Linkify.addLinks(s, Linkify.WEB_URLS);
		  message.setText(s);
		  message.setMovementMethod(LinkMovementMethod.getInstance());

		  return new AlertDialog.Builder(context)
		   .setTitle(R.string.about)
		   .setCancelable(true)
		   .setIcon(android.R.drawable.ic_dialog_info)
		   .setPositiveButton("OK", null)
		   .setView(message)
		   .create();
		 }
		}
}
